/*
 * 
 *	Copyright © 2013 Changsha Shishuo Network Technology Co., Ltd. All rights reserved.
 *	长沙市师说网络科技有限公司 版权所有
 *	http://www.shishuo.com
 *
 *	Licensed under the Apache License, Version 2.0 (the "License");
 *	you may not use this file except in compliance with the License.
 *	You may obtain a copy of the License at
 *	 
 *		http://www.apache.org/licenses/LICENSE-2.0
 *
 *	Unless required by applicable law or agreed to in writing, software
 *	distributed under the License is distributed on an "AS IS" BASIS,
 *	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *	See the License for the specific language governing permissions and
 *	limitations under the License.
 */
package com.shishuo.cms;

import java.awt.Toolkit;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Properties;

import javax.swing.JOptionPane;

/**
 *
 * @author Herbert
 */
public class App extends javax.swing.JFrame {
	
	/**
	 * 
	 */
	private static String CMS_PROPERTIES = "shishuocms.properties";
	/**
	 * 
	 */
	private static String CMS_INSTALL_SQL = "sql/install.sql";

    /**
     * Creates new form App
     */
    public App() {    
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        logo = new javax.swing.JLabel();
        databaseSetting = new javax.swing.JPanel();
        jLabelIp = new javax.swing.JLabel();
        jLabelPort = new javax.swing.JLabel();
        jLabelDatabase = new javax.swing.JLabel();
        jLabelUsername = new javax.swing.JLabel();
        jLabelPassword = new javax.swing.JLabel();
        ip = new javax.swing.JTextField();
        port = new javax.swing.JTextField();
        database = new javax.swing.JTextField();
        username = new javax.swing.JTextField();
        password = new javax.swing.JTextField();
        systemSetting = new javax.swing.JPanel();
        jLabelAdminEmail = new javax.swing.JLabel();
        jLabelAdminPassword = new javax.swing.JLabel();
        jLabelAdminPassword1 = new javax.swing.JLabel();
        adminEmail = new javax.swing.JTextField();
        adminPassword = new javax.swing.JPasswordField();
        adminPassword1 = new javax.swing.JPasswordField();
        submit = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("欢迎使用“师说CMS”安装程序");

//        logo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/shishuo/install/logo.png"))); // NOI18N
        logo.setIcon(new javax.swing.ImageIcon(getClass().getResource("logo.png"))); // NOI18N
        
        databaseSetting.setBorder(javax.swing.BorderFactory.createTitledBorder("数据库设置"));
        databaseSetting.setToolTipText("");
        databaseSetting.setName("数据库设置"); // NOI18N

        jLabelIp.setText("数据库地址：");

        jLabelPort.setText("数据库端口：");

        jLabelDatabase.setText("数据库名称：");

        jLabelUsername.setText("用   户   名：");

        jLabelPassword.setText("密          码：");

        ip.setText("127.0.0.1");

        port.setText("3306");

        database.setText("shishuocms");

        username.setText("root");

        javax.swing.GroupLayout databaseSettingLayout = new javax.swing.GroupLayout(databaseSetting);
        databaseSetting.setLayout(databaseSettingLayout);
        databaseSettingLayout.setHorizontalGroup(
            databaseSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(databaseSettingLayout.createSequentialGroup()
                .addGap(55, 55, 55)
                .addGroup(databaseSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelPort)
                    .addComponent(jLabelPassword)
                    .addGroup(databaseSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabelDatabase)
                        .addComponent(jLabelUsername))
                    .addComponent(jLabelIp))
                .addGap(18, 18, 18)
                .addGroup(databaseSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(ip)
                    .addComponent(port)
                    .addComponent(database, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
                    .addComponent(username)
                    .addComponent(password))
                .addContainerGap(60, Short.MAX_VALUE))
        );
        databaseSettingLayout.setVerticalGroup(
            databaseSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(databaseSettingLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(databaseSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelIp)
                    .addComponent(ip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(databaseSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelPort)
                    .addComponent(port, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(databaseSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(database, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelDatabase))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(databaseSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelUsername))
                .addGap(3, 3, 3)
                .addGroup(databaseSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelPassword)
                    .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        systemSetting.setBorder(javax.swing.BorderFactory.createTitledBorder("管理员设置"));

        jLabelAdminEmail.setText("邮箱地址：");

        jLabelAdminPassword.setText("再输入一次密码：");

        jLabelAdminPassword1.setText("密      码：");

        javax.swing.GroupLayout systemSettingLayout = new javax.swing.GroupLayout(systemSetting);
        systemSetting.setLayout(systemSettingLayout);
        systemSettingLayout.setHorizontalGroup(
            systemSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(systemSettingLayout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(systemSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelAdminPassword1)
                    .addComponent(jLabelAdminPassword)
                    .addComponent(jLabelAdminEmail))
                .addGap(18, 18, 18)
                .addGroup(systemSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(adminEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
                    .addComponent(adminPassword)
                    .addComponent(adminPassword1))
                .addContainerGap(58, Short.MAX_VALUE))
        );
        systemSettingLayout.setVerticalGroup(
            systemSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(systemSettingLayout.createSequentialGroup()
                .addGroup(systemSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelAdminEmail)
                    .addComponent(adminEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(systemSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelAdminPassword1)
                    .addComponent(adminPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(systemSettingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelAdminPassword)
                    .addComponent(adminPassword1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 8, Short.MAX_VALUE))
        );

        submit.setText("安装");
        submit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(19, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(databaseSetting, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(systemSetting, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(19, 19, 19))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(logo)
                            .addGap(146, 146, 146)))))
            .addGroup(layout.createSequentialGroup()
                .addGap(176, 176, 176)
                .addComponent(submit, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(logo)
                .addGap(18, 18, 18)
                .addComponent(databaseSetting, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(systemSetting, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(submit, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                                                               

    private void submitActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
    	ip.setToolTipText("ip错误");
    	
		try {
			BufferedInputStream bis = new BufferedInputStream(
					new FileInputStream(CMS_PROPERTIES));
			Properties props = new Properties();
		} catch (FileNotFoundException e) {
			JOptionPane.showMessageDialog(null,"警告消息");
		}
		
    	
    	
    }                                      

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(App.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(App.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(App.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(App.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                App app = new App();
                double width = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
      double height = Toolkit.getDefaultToolkit().getScreenSize().getHeight();
     app.setLocation( (int) (width - app.getWidth()) / 2,
                  (int) (height - app.getHeight()) / 2);    
                app.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JTextField adminEmail;
    private javax.swing.JPasswordField adminPassword;
    private javax.swing.JPasswordField adminPassword1;
    private javax.swing.JTextField database;
    private javax.swing.JPanel databaseSetting;
    private javax.swing.JTextField ip;
    private javax.swing.JLabel jLabelAdminEmail;
    private javax.swing.JLabel jLabelAdminPassword;
    private javax.swing.JLabel jLabelAdminPassword1;
    private javax.swing.JLabel jLabelDatabase;
    private javax.swing.JLabel jLabelIp;
    private javax.swing.JLabel jLabelPassword;
    private javax.swing.JLabel jLabelPort;
    private javax.swing.JLabel jLabelUsername;
    private javax.swing.JLabel logo;
    private javax.swing.JTextField password;
    private javax.swing.JTextField port;
    private javax.swing.JButton submit;
    private javax.swing.JPanel systemSetting;
    private javax.swing.JTextField username;
    // End of variables declaration                   
}
